//package eu.games.esmi.ieat.indicatorvalues.data;
//
//import java.io.PrintWriter;
//import java.sql.Connection;
//import java.sql.DriverManager;
//
//import org.olap4j.Axis;
//import org.olap4j.CellSet;
//import org.olap4j.OlapConnection;
//import org.olap4j.layout.RectangularCellSetFormatter;
//import org.olap4j.metadata.Cube;
//import org.olap4j.metadata.Dimension;
//import org.olap4j.query.Query;
//import org.olap4j.query.QueryDimension;
//
//public class OLAPManager {
//    
//    
//    /*
//     * SELECT t.hour, min(value), avg(value), max(value)
//FROM (`stored-values-olap`.`values_facts` as v join `stored-values-olap`.`time_dim` as t on v.time_id=t.time_id) 
//where gpi_kpi_id=6 and component_id=20 and t.year=2012 and t.month=5 and t.day=12 group by t.hour;
//     * 
//     */
//    static OlapConnection olapConnection;        
//    static String query = "SELECT {[Component].[Component Category].[Server].[Server12],[Component].[Component Category].[Server].[Server14],[Component].[Component Category].[Server].[Server16],[Component].[Component Category].[Server].[Server17],[Component].[Component Category].[Server].[Server18]} ON COLUMNS, {[Time].[2012].[5].CHILDREN} ON ROWS FROM [StoredValues] WHERE (Measures.[Average value],[GPI].[GPI-KPI Name].[Server Consumption])";
////      static String query = "SELECT {[Component].[Component Category].[Memory].[Mem12],[Component].[Component Category].[Memory].[Mem14],[Component].[Component Category].[Memory].[Mem16],[Component].[Component Category].[Memory].[Mem17],[Component].[Component Category].[Memory].[Mem18]} ON COLUMNS, {[Time].[2012].[5].[12].CHILDREN} ON ROWS FROM [StoredValues] WHERE (Measures.[Average value],[GPI].[GPI-KPI Name].[Memory Usage])";
////      static String query = "SELECT {[Component].[Component Category].[CPU].[CPU12],[Component].[Component Category].[CPU].[CPU14],[Component].[Component Category].[CPU].[CPU16],[Component].[Component Category].[CPU].[CPU17],[Component].[Component Category].[CPU].[CPU18]} ON COLUMNS, {[Time].[2012].[5].[12].CHILDREN} ON ROWS FROM [StoredValues] WHERE (Measures.[Average value],[GPI].[GPI-KPI Name].[CPU Usage])";
////      static String query = "SELECT {[Measures].[Min value],[Measures].[Average value], [Measures].[Max value]} ON COLUMNS, {[Time].[2012].[5].[12].CHILDREN} ON ROWS FROM [StoredValues] WHERE ([GPI].[GPI-KPI Name].[CPU Usage])";
//
//    public static void main(String[] args) throws Exception {
//        
//       // Load the driver
//        Class.forName("mondrian.olap4j.MondrianOlap4jDriver");
//        
//        // Connect
//        final Connection connection =
//            DriverManager.getConnection(
//            "jdbc:mondrian:"                                                            // Driver ident
//            + "Jdbc=jdbc:mysql://localhost:3306/stored-values-olap?user=epkb&password=epkb;"                                // Relational DB
//            + "Catalog=file:olapschema/indicators.xml;");                                   // Catalog
//        
// // We are dealing with an olap connection. we must unwrap it.
//        olapConnection = connection.unwrap(OlapConnection.class);
//
//        
//        for (Dimension d:olapConnection
//                .getOlapSchema()
//                    .getCubes()
//                        .get("StoredValues").getDimensions()) {
//        System.err.println(d.getName());
//        }
//        // Get a cube object.
//        Cube salesCube = 
//            olapConnection
//                .getOlapSchema()
//                    .getCubes()
//                        .get("StoredValues");
//                
//        // Build a query object.
//        Query myQuery =
//            new Query(
//                "myQuery", 
//                salesCube);
//
//        final CellSet cellSet = olapConnection
//            .createStatement()              // Prepare a statement
//                .executeOlapQuery(query);   // Execute some query
//
//        
//     
//
//        // Including a member by metadata
//        /*Member year1997 =
//            salesCube.lookupMember(
//                IdentifierNode.ofNames("anno", "2011")
//                    .getSegmentList());
//        tempoDim.include(year1997);
//*/
//
//        // Including a member by name parts
//        /*productDim.include(
//            Selection.Operator.CHILDREN,
//            IdentifierNode.ofNames(
//                "Product", 
//                "Drink",
//                "Beverages")
//                    .getSegmentList());
//            */
//
//        // We can also exclude members
//        /*productDim.exclude(
//            IdentifierNode.ofNames(
//                "Product", 
//                "Drink", 
//                "Beverages",
//                "Carbonated Beverages")
//                    .getSegmentList());
//*/
//        // Validate this query
//       
//        //myQuery.validate();
//
//        // Print!
//        System.out.println("/********************* QUERY ***********************/");
//
//        System.out.println(myQuery.getSelect().toString());
//
//        System.out.println("/********************* QUERY ***********************/");
//        System.out.println(" ");
//        System.out.println(" ");
//        System.out.println(" ");
//        System.out.println(" ");
//
//        System.out.println("/********************* RESULTS ***********************/");
//
//        RectangularCellSetFormatter formatter =
//            new RectangularCellSetFormatter(false);
//
//        PrintWriter writer = new PrintWriter(System.out);
//
//        formatter.format(
//            cellSet, // myQuery.execute(), 
//            writer);
//
//        writer.flush();
//        System.out.println("/********************* RESULTS ***********************/");
//    }
//}